
var mensajeConfirmarBorrado = "Esta seguro que desea eliminar el registro seleccionado?";

function limpiarFormulario(formulario){
	alert(formulario);
}

function verificarAgregadoRechazado(obj) {
	var objChecked = obj.checked;
	if (objChecked) {
		var objId = obj.id;
		if (objId.indexOf('aceptado') > 0) {
			objId = objId.replace('aceptado', 'rechazado');
		} else if (objId.indexOf('rechazado') > 0) {
			objId = objId.replace('rechazado', 'aceptado');
		}

		var nObj = document.getElementById(objId);
		if (nObj) {
			if (nObj.checked) {
				nObj.checked = false;
			}
		}
	}}

function abrirPopup(url) {
	opciones = "left=0, top=0, screenX=0, screenY=100, width=950, height=500, "
			+ "copyhistory=no, directories=no, resizable=no, titlebar=no, "
			+ "toolbar=no, scrollbars=yes, location=0, menubar=0, dependent=yes";
	window.open(url, "", opciones);
}

function abrirConsultaJuridica(url){
	opciones = "left=0, top=0, "
		+ "copyhistory=no, directories=no, resizable=yes, titlebar=no, "
		+ "toolbar=no, scrollbars=yes, location=0, menubar=0, dependent=yes";
	window.open(url, "", opciones);
}

function verificarSecretariaDireccion(obj) {
	var objChecked = obj.checked;
	if (objChecked) {
		var objId = obj.id;
		if (objId.indexOf('aSecretaria') > 0) {
			objId = objId.replace('aSecretaria', 'aDireccion');
		} else if (objId.indexOf('aDireccion') > 0) {
			objId = objId.replace('aDireccion', 'aSecretaria');
		}

		var nObj = document.getElementById(objId);
		if (nObj) {
			if (nObj.checked) {
				nObj.checked = false;
			}
		}
	}
}

function verificarFirmadoDevuelto(obj) {
	var objChecked = obj.checked;
	if (objChecked) {
		var objId = obj.id;
		if (objId.indexOf('firmado') > 0) {
			objId = objId.replace('firmado', 'devuelto');
		} else if (objId.indexOf('devuelto') > 0) {
			objId = objId.replace('devuelto', 'firmado');
		}

		var nObj = document.getElementById(objId);
		if (nObj) {
			if (nObj.checked) {
				nObj.checked = false;
			}
		}
	}
}

function TrimString(sInString) {
	sInString = sInString.replace(/^\s+/g, "");
	return sInString.replace(/\s+$/g, "");
}

function openReportWindow(url) {
	var reportWindow = window.open(url, "reportWindow",
			"menubar=0,resizable=0,status=0,width=640,height=480");
}

function toggleCheckAll(formName, controlName, value, exclude) {
	var formObject = document.getElementById(formName);
	if (formObject) {
		var elements = formObject.elements;
		for (var i = 0; i < elements.length; i++) {
			var element = elements[i];
			if (element.type == 'checkbox') {
				if (element.id != null && element.id.indexOf(controlName) != -1) {
					element.checked = value;
				} else if (exclude) {
					element.checked = false;
				}
			}
		}
	}
}

function setFocus(componentName) {
	var component = document.getElementById(componentName);
	if (component) {
		component.focus();
	}
}

function esIE() {
	if (document.all) {
		return true;
	}
	return false;
}

function aceptarLetras(evt) {
	var key = null;
	if (esIE()) {
		key = evt.keyCode;
	} else {
		key = evt.which;
	}
	return (key == 0 || key == 8 || key == 32 ||
			(key >= 64 && key <= 90) ||
			(key >= 97 && key <= 122) ||
			key == 209 || key == 241);
}

function aceptarNumerosLetras(evt) {
	var key = null;
	if (esIE()) {
		key = evt.keyCode;
	} else {
		key = evt.which;
	}
	return ((key == 0 || key == 8 || key == 32) ||
			(key >= 48 && key <= 57) || 
			(key >= 64 && key <= 90) || 
			(key >= 97 && key <= 122));
}

function aceptarNumerosLetrasYGuiones(evt) {
	var key = null;
	if (esIE()) { 
		key = evt.keyCode;
	} else {
		key = evt.which;
	}
	return (key == 45 || key == 8 || key == 0 || 
			(key >= 48 && key <= 57) || 
			(key >= 64 && key <= 90) || 
			(key >= 97 && key <= 122));
}

function aceptarNumeros(evt) {
	var key = null;
	if (esIE()) {
		key = evt.keyCode;
	} else {
		key = evt.which;
	}
	
	return (key == 8 || key ==0 || (key >= 48 && key <= 57));
}
function aceptarNumerosDecimales(evt) {
	var key = null;
	if (esIE()) {
		key = evt.keyCode;
	} else {
		key = evt.which;
	}
	
	return (key ==46 || key == 8 || key ==0 || (key >= 48 && key <= 57));
}

function aceptarNumerosDecimales2(evt,enteros,decimales,campo) {
	tecla = (document.all) ? evt.keyCode : evt.which;
	if (tecla == 8 ||tecla == 0)
		return true; 

	var pDecimal = new RegExp("^[0-9]{1,"+enteros+"}(\\.[0-9]{0,"+decimales+"})?$","g");

	return pDecimal.test(campo.value+String.fromCharCode(tecla));
}

function aceptarNumerosYComodines(evt) {
	var key = null;
	
	if (esIE()) {
		key = evt.keyCode;
	} else {
		key = evt.which;
	}
	
	return (key == 95 || key == 37 || key == 8  || key == 0 || (key >= 48 && key <= 57));
}

function vocalConTilde(key){
	return (key == 225 || key == 233|| key == 237|| key == 243|| key == 250);
}

function aceptarNumerosLetrasCaracteresSpeciales(evt){
	var key = null;
	if (esIE()) {
		key = evt.keyCode;
	} else {
		key = evt.which;
	}
	return ((key >= 48 && key <= 57) || (key >= 64 && key <= 90) || (key >= 97 && key <= 122) || key == 32 || key == 45 || key == 241
			|| key == 209 || key == 8 || vocalConTilde(key));
}



function aceptarNumerosYGuiones(evt) {
	var key = null;
	if (esIE()) {
		key = evt.keyCode;
	} else {
		key = evt.which;
	}
	return (key == 45 || key == 8 || key == 0 || (key >= 48 && key <= 57));
}

function aceptarCioRuc(campo){
	var long = campo.value.length;
	if((long != 10 && long != 13) && (long > 0)){
		if(long < 10){
			alert("Cedula Incorrecta");
		} else if(long > 10 && long <13){
			alert("RUC Incorrecto");
		}
		campo.focus();
	}
	
}

function aceptarFecha(evt) {
	var key = null;
	if (esIE()) {
		key = evt.keyCode;
	} else {
		key = evt.which;
	}
	

	return (key >= 47 && key <= 57) || key == 8 || key == 0;
}

function popUp(url, alto, ancho) {
	var left   = (screen.width  - ancho)/2;
	 var top    = (screen.height - alto)/2;
	 var params = 'width='+ancho+', height='+alto;
	 params += ', top='+top+', left='+left;
	 params += ', directories=no';
	 params += ', location=no';
	 params += ', menubar=no';
	 params += ', resizable=no';
	 params += ', scrollbars=yes';
	 params += ', status=no';
	 params += ', toolbar=no';
	 newwin=window.open(url,'SRI', params);
	 if (window.focus) {newwin.focus()}
	 return false;
}

function updateParentWindow(nombreForm,nombreBotonRenderizado) {
	
	var elementToGet = nombreForm + ":" + nombreBotonRenderizado;
	var bt= opener.document.forms[nombreForm].elements[elementToGet]
	bt.click();
	window.close();
}

function refreshParentWindow() {
	opener.location.reload(true);
	window.close();
}

function confirmarSubmit(mensaje)
{
	var acepta=confirm(mensaje);
	if (acepta)
		return true ;
	else
		return false ;
       
}

/* Validaci�n de fechas */

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("El formato de fecha debe ser : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Por favor ingrese un mes v�lido")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Por favor ingrese un d�a v�lido")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Por favor ingrese un a�o v�lido de 4 d�gitos entre  "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Por favor ingrese una fecha v�lida")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }

//Funci�n nueva Control de check
function mensajeSeleccionar(mensaje,id,formulario){
	   //alert("entraste");
	  	 var elementToGet = formulario + ":" + id;
		 var bt= document.forms[formulario].elements[elementToGet].checked;
		 if(bt) alert(mensaje);
	  } 

function ejecutarClick(evt,elemento){
	var key = null;
	if (esIE()) {
		key = evt.keyCode;
	} else {
		key = evt.which;
	}
	if(key == 13){
		fireEvent(document.getElementById(elemento),'click');
	}
}

function fireEvent(obj,evt){
	
	var fireOnThis = obj;
	if( document.createEvent ) {
	  var evObj = document.createEvent('MouseEvents');
	  evObj.initEvent( evt, true, false );
	  fireOnThis.dispatchEvent(evObj);
	} else if( document.createEventObject ) {
	  fireOnThis.fireEvent('on'+evt);
	}
}

function checkOnlyOne (e,id){
	id = id + "$";
	var regExp = new RegExp(id);
	var elementos = getElementsByRegExpId(regExp,document,"input");
	for(var i=0; i<elementos.length; i++){
		elementos[i].checked=0;
	}
	e.checked=1;
}

function getElementsByRegExpId(p_regexp, p_element, p_tagName) {
	p_element = p_element === undefined ? document : p_element;
	p_tagName = p_tagName === undefined ? '*' : p_tagName;
	var v_return = [];
	var v_inc = 0;
	for(var v_i = 0, v_il = p_element.getElementsByTagName(p_tagName).length; v_i < v_il; v_i++) {
		if(p_element.getElementsByTagName(p_tagName).item(v_i).id && p_element.getElementsByTagName(p_tagName).item(v_i).id.match(p_regexp)) {
			v_return[v_inc] = p_element.getElementsByTagName(p_tagName).item(v_i);
			v_inc++;
		}
	}
	return v_return;
}
/* FUNCION QUE FIJA EL TAMA�O DE LAS VENTANAS DE POP-UP DE ACUERDO A LA RESOLUCION DE LA PANTALLA EN EL CLIENTE */
function redimensionaVentana(){
	var ancho, alto, xPos, yPos;
	ancho = screen.width;
	alto = screen.height / 1.5;
	xPos = screen.width / 120;
	yPos = screen.height / 10;
	
	self.resizeTo(ancho, alto);
	self.moveTo(xPos, yPos);
}


